home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / pwrwin.exe / DLG.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-01-15  |  25.8 KB  |  881 lines

  1. #include <stdio.h>
  2. #include <io.h>
  3. #include <dos.h>
  4. #include <bios.h>
  5. #include "pw.h"
  6.  
  7. #define ALT_KEY         ((*(char far *) (config+0x17)) & 0x8)
  8.  
  9. struct ListBox { struct NodeHead TextNodeHead;
  10.          unsigned count;
  11.          int pos, displayoffset;
  12.            };
  13.  
  14. char far *config = (char far *) 0x400000;
  15. char far *screenptr = (char far *) 0xB8000000;
  16.  
  17. struct Border        BoldBorder = { '╔','╗','╝','╚','║','═' };
  18. struct Border        NormalBorder = { '┌','┐','┘','└','│','─' };
  19.  
  20. long ButtonProc ( WINDOW *, unsigned,int, long);
  21. long EditProc ( WINDOW *, unsigned, int, long);
  22. long ListBoxProc ( WINDOW *, unsigned, int, long);
  23.  
  24. void (interrupt far *oldTimerProc) ();
  25. int timerenabled = TRUE, mouse;
  26. int ExitLoop=FALSE,RetCode;
  27.  
  28. int AddClass ( char *, long (*)());
  29.  
  30. struct NodeHead         ClassNode;
  31. struct NodeHead         WindowNode;
  32. struct NodeHead         EditNode;
  33. struct NodeHead         TimerNode;
  34. struct NodeHead         NodeListHead;
  35.  
  36. int                menucheck=FALSE;
  37. int                classcount=0;
  38. int                             cursorchanged=TRUE;
  39. int                             oldcursorpos;
  40.  
  41. /******************************************************************************/
  42. /******************************************************************************/
  43.  
  44. void strrcopy ( char *target, char *source)
  45. {
  46. register unsigned i,l;
  47.   for (i=l=strlen(source);i>1;i--) *(target+i) = *(source+i);
  48.   *(target+l) = 0;
  49. }
  50.  
  51. /******************************************************************************/
  52.  
  53. int Clear ( struct Window *Window)
  54. {
  55. register unsigned x, y;
  56.  
  57.    for (y=0;y<Window->CRect.height;y++) {
  58.     SetCursor ( Window, 0, y);
  59.     for (x=0;x<Window->CRect.width;x++) OutChar ( Window, ' ');
  60.     }
  61. }
  62.  
  63. /******************************************************************************/
  64.  
  65. void interrupt far TimerProc ( es, ds, di, si, bp, sp, bx, dx, cx, ax, ip, cs, flags)
  66. unsigned es, ds, di, si, bp, sp, bx, dx, cx, ax, ip, cs, flags;
  67. {
  68. static struct TimerInfo *TimerInfo;
  69. struct Node *Node = TimerNode.FirstNode;
  70.  
  71.    if (timerenabled && (TimerInfo = (struct TimerInfo *) Node->Item)) {
  72.      do {
  73.          if (TimerInfo->Time_to_go) TimerInfo->Time_to_go--;
  74.          Node = Node->NextNode;
  75.        } while (TimerInfo = (struct TimerInfo *) Node->Item);
  76.      }
  77.  _chain_intr ( oldTimerProc);
  78. }
  79.  
  80. /******************************************************************************/
  81.  
  82. void Intr ( unsigned ax, unsigned bx, unsigned cx, unsigned dx)
  83. {
  84. union REGS InRegs, OutRegs;
  85. struct SREGS SegRegs;
  86.  
  87.  segread (&SegRegs);
  88.  InRegs.x.ax = ax;
  89.  InRegs.x.bx = bx;
  90.  InRegs.x.cx = cx;
  91.  InRegs.x.dx = dx;
  92.  
  93.  int86x ( 0x10 ,&InRegs, &OutRegs, &SegRegs);
  94. }
  95.  
  96.  
  97. int SetTimer ( struct Window *Window, unsigned time)
  98. {
  99. struct TimerInfo *TimerInfo;
  100.  
  101.    if (!(TimerInfo = (struct TimerInfo *) malloc ( sizeof (struct TimerInfo)))) return FALSE;
  102.    TimerInfo->Time = TimerInfo->Time_to_go = time;
  103.    TimerInfo->Window = Window;
  104.    timerenabled = FALSE;
  105.    AddNode ( &TimerNode, (int) TimerInfo);
  106.    timerenabled = TRUE;
  107. return (int) (TimerInfo);
  108. }
  109.  
  110. /******************************************************************************/
  111.  
  112. int KillTimer ( int Timer)
  113. {
  114.  timerenabled = FALSE;
  115.  DeleteNode ( &TimerNode, Timer);
  116.  timerenabled = TRUE;
  117.  free ((char *) Timer);
  118. return TRUE;
  119. }
  120.  
  121. /******************************************************************************/
  122.  
  123. int CheckTimer ()
  124. {
  125. static struct TimerInfo *TimerInfo;
  126. struct Node *Node = TimerNode.FirstNode;
  127.  
  128.    if (!(TimerInfo = (struct TimerInfo *) GetNode ( &TimerNode, 0, GN_FIRST))) return FALSE;
  129.    do {
  130.     if (TimerInfo->Time_to_go) continue;
  131.     SendMessage ( TimerInfo->Window, WM_TIMER, 0, 0L);
  132.     TimerInfo->Time_to_go = TimerInfo->Time;
  133.       } while ( TimerInfo = (struct TimerInfo *) GetNode ( &TimerNode, (int) TimerInfo, GN_NEXT));
  134. return TRUE;
  135. }
  136.  
  137. /******************************************************************************/
  138.  
  139. int _memcpy ( char far *target, char far *source, unsigned count)
  140. {
  141. register unsigned i;
  142.   for (i=0;i<count;i++) *target++ = *source++;
  143. return 1;
  144. }
  145.  
  146. /******************************************************************************/
  147.  
  148. int ScrollWindow ( struct Window *Window, int rx, int ry)
  149. {
  150. register int y, x, in, i;
  151.  
  152.  if (ry==-1) {
  153.     for (y=1;y<=Window->CRect.height;y++)
  154.         for (x=0;x<Window->CRect.width;x++) {
  155.             in = ReadPoint ( Window, x, y);
  156.             SetCursor ( Window, x, y-1);
  157.             OutChar ( Window, (char) in);
  158.             }
  159.     for (x=0;x<Window->CRect.width;x++) {
  160.         SetCursor ( Window, x, Window->CRect.height-1);
  161.         OutChar ( Window, (char) ' ');
  162.         }
  163.     }
  164.  
  165.  if (ry==1) {
  166.         for (y=Window->CRect.height-1;y;y--)
  167.         for (x=0;x<Window->CRect.width;x++) {
  168.                         in = ReadPoint ( Window, x, y-1);
  169.                         SetCursor ( Window, x, y);
  170.             OutChar ( Window, (char) in);
  171.             }
  172.     for (x=0;x<Window->CRect.width;x++) {
  173.         SetCursor ( Window, x, 0);
  174.         OutChar ( Window, (char) ' ');
  175.         }
  176.     }
  177.  
  178.  if (rx==1) {
  179.     for (y=0;y<Window->CRect.height;y++)
  180.         for (x=0;x<Window->CRect.width-1;x++) {
  181.             in = ReadPoint ( Window, x, y);
  182.             SetCursor ( Window, x+1, y);
  183.             OutChar ( Window, (char) in);
  184.             }
  185.     for (y=0;y<Window->CRect.height;y++) {
  186.         SetCursor ( Window, 0, y);
  187.         OutChar ( Window, (char) ' ');
  188.         }
  189.     }
  190.  
  191.  if (rx==-1) {
  192.     for (y=0;y<Window->CRect.height;y++)
  193.         for (x=1;x<Window->CRect.width;x++) {
  194.             in = ReadPoint ( Window, x, y);
  195.             SetCursor ( Window, x-1, y);
  196.             OutChar ( Window, (char) in);
  197.             }
  198.     for (y=0;y<Window->CRect.height;y++) {
  199.         SetCursor ( Window, Window->CRect.height-1, y);
  200.         OutChar ( Window, (char) ' ');
  201.         }
  202.     }
  203. }
  204.  
  205. /******************************************************************************/
  206.  
  207. int SetCursor ( struct Window *Window, int x, int y)
  208. {
  209.  Window->xcur = x;
  210.  Window->ycur = y;
  211. }
  212.  
  213. /******************************************************************************/
  214.  
  215. struct Window *IfWindow ( struct Window *Window, int x, int y)
  216. {
  217. struct Window *RunWindow = Window;
  218.    while (RunWindow = (struct Window *) GetNode ( &WindowNode, (int) RunWindow, GN_NEXT))
  219.        if (PtInRect( Window->CRect.x+x, Window->CRect.y+y, (struct Rect *) &RunWindow->x)) return RunWindow;
  220. return 0;
  221. }
  222.  
  223. /******************************************************************************/
  224.  
  225. int PtInRect ( int x, int y, struct Rect *Rect)
  226. {
  227. int left = Rect->x,
  228.     right = left + Rect->width,
  229.     top = Rect->y,
  230.     bottom = top + Rect->height;
  231.  
  232.   if (!((x>=left) && (x<right))) return FALSE;
  233.   if (!((y>=top) && (y<bottom))) return FALSE;
  234. return TRUE;
  235. }
  236.  
  237. /******************************************************************************/
  238.  
  239. int ReadPoint ( struct Window *Window , int x, int y)
  240. {
  241. int far *scrpos, *mempos=0;
  242. struct Window *RunWindow = Window;
  243. int xpos, ypos;
  244.  
  245.    if (!PtInRect ( Window->CRect.x+x, Window->CRect.y+y, (struct Rect *) &Window->CRect)) return -1;
  246.  
  247.    while (RunWindow = (struct Window *) GetNode ( &WindowNode, (int) RunWindow, GN_NEXT))
  248.        if (PtInRect( Window->CRect.x+x, Window->CRect.y+y, (struct Rect *) &RunWindow->x)) {
  249.         xpos = (Window->CRect.x+x) - RunWindow->x;
  250.         ypos = (Window->CRect.y+y) - RunWindow->y;
  251.         mempos = (int *) ((RunWindow->buffer + (ypos*((RunWindow->width)*2)) + (xpos*2)));
  252.         return *mempos;
  253.         break;
  254.         }
  255.    if (!mempos) {
  256.     scrpos = (int far *) (screenptr + Window->CRect.x*2 + Window->CRect.y*160 + x*2 + y*160);
  257.     return *scrpos;
  258.     }
  259. }
  260.  
  261. /******************************************************************************/
  262.  
  263. int OutChar ( struct Window *Window ,char out)
  264. {
  265. char far *scrpos, *mempos=0;
  266. struct Window *RunWindow = Window;
  267. int x, y;
  268.  
  269.    if (!PtInRect ( Window->CRect.x+Window->xcur, Window->CRect.y+Window->ycur, (struct Rect *) &Window->CRect)) return FALSE;
  270.  
  271.    while (RunWindow = (struct Window *) GetNode ( &WindowNode, (int) RunWindow, GN_NEXT))
  272.        if (PtInRect( Window->CRect.x+Window->xcur, Window->CRect.y+Window->ycur, (struct Rect *) &RunWindow->x)) {
  273.         x = (Window->CRect.x+Window->xcur) - RunWindow->x;
  274.         y = (Window->CRect.y+Window->ycur) - RunWindow->y;
  275.         mempos = (RunWindow->buffer + (y*((RunWindow->width)*2)) + (x*2));
  276.         *mempos = out;
  277.         *++mempos = Window->textcolor;
  278.         break;
  279.         }
  280.    if (!mempos) {
  281.     scrpos = (char far *) (screenptr + Window->CRect.x*2 + Window->CRect.y*160 + Window->xcur*2 + Window->ycur*160);
  282.     *scrpos = out;
  283.     *++scrpos = Window->textcolor;
  284.     }
  285.    Window->xcur++;
  286.    cursorchanged = TRUE;
  287. return out;
  288. }
  289.  
  290. /******************************************************************************/
  291.  
  292. int OutText ( struct Window *Window, int x, int y, char *text, int count)
  293. {
  294.  SetCursor ( Window, x, y);
  295.  while ( *text && count--) OutChar ( Window, *text++);
  296. return 1;
  297. }
  298.  
  299. int Text ( struct Window *Window, char *text)
  300. {
  301.  while ( *text) OutChar ( Window, *text++);
  302. return 1;
  303. }
  304.  
  305. /******************************************************************************/
  306.  
  307. int SetBCursor ( struct Window *Window)
  308. {
  309. unsigned x, y;
  310.   x = Window->CRect.x + Window->xcur;
  311.   y = Window->CRect.y + Window->ycur;
  312.   if ( IfWindow (Window, x, y)) x = y = 0;
  313.   Intr ( 0x0200, 0, 0, x | y<<8);
  314. }
  315.  
  316. /******************************************************************************/
  317.  
  318. int InitClass ()
  319. {
  320. static char *button = "button",
  321.         *edit = "edit",
  322.         *listbox = "listbox";
  323. struct Class *Class;
  324.  
  325.  if (!(Class = (struct Class *) malloc (sizeof(struct Class)))) return FALSE;
  326.  strcpy (Class->classname, button);
  327.  Class->function  = ButtonProc;
  328.  AddNode ( &ClassNode, (int) Class);
  329.  classcount = 1;
  330.  
  331.  AddClass ( edit, EditProc);
  332.  AddClass ( listbox, ListBoxProc);
  333. return TRUE;
  334. }
  335.  
  336. /******************************************************************************/
  337.  
  338. int AddClass ( char *name, long (*function)())
  339. {
  340. struct Class *Class;
  341.  
  342.  if (!function || !name[0]) return FALSE;
  343.  if (!(Class = (struct Class *) malloc (sizeof(struct Class)))) return FALSE;
  344.  strcpy ( Class->classname, name);
  345.  Class->function = function;
  346.  AddNode ( &ClassNode, (int) Class);
  347. return ++classcount;
  348. }
  349.  
  350. /******************************************************************************/
  351.  
  352. void InitAll ()
  353. {
  354.  union REGS InRegs, OutRegs;
  355.  InitClass ();
  356.  
  357.  oldTimerProc = _dos_getvect ( DOSTIMER);
  358.  _dos_setvect ( DOSTIMER, TimerProc);
  359.  
  360.  InRegs.x.ax = 0x0300;
  361.  InRegs.x.bx = 0;
  362.  int86 ( 0x10 ,&InRegs, &OutRegs);
  363.  oldcursorpos = OutRegs.x.dx;
  364. }
  365.  
  366. /******************************************************************************/
  367.  
  368. void CloseAll ()
  369. {
  370.  union REGS InRegs, OutRegs;
  371.  
  372.  _dos_setvect ( DOSTIMER, oldTimerProc);
  373.  
  374.  InRegs.x.ax = 0x0200;
  375.  InRegs.x.bx = 0;
  376.  InRegs.x.dx = oldcursorpos;
  377.  int86 ( 0x10 ,&InRegs, &OutRegs);
  378. }
  379.  
  380. /******************************************************************************/
  381.  
  382. int SendMessage ( struct Window *Window, unsigned Message, int wParam, long lParam)
  383. {
  384.  if ( !Window) return -1;
  385. return (*Window->function)( Window, Message, wParam, lParam);
  386. }
  387.  
  388. /******************************************************************************/
  389.  
  390. int GetClientRect ( struct Window *Window, struct Rect *Rect)
  391. {
  392.  Rect->x = Rect->y = 0;
  393.  Rect->width = Window->CRect.width;
  394.  Rect->height = Window->CRect.height;
  395. return TRUE;
  396. }
  397.  
  398. /******************************************************************************/
  399.  
  400. int DestroyWindow ( struct Window *Window)
  401. {
  402. register int i;
  403. register int far *scrpos;
  404.  
  405.  if ( !Window) return FALSE;
  406.  SendMessage ( Window, WM_DESTROY, 0, 0L);
  407.  for (i=0;i<Window->height;i++)
  408.     _memcpy ((char far *) screenptr+Window->y*160+Window->x*2+i*160, (char far *) Window->buffer+i*Window->width*2, Window->width*2);
  409.  free ( Window->buffer);
  410.  DeleteNode ( &WindowNode, (int) Window);
  411.  if (Window->MainWindow) DeleteNode ( &(Window->MainWindow->ChildNode), (int) Window);
  412.  free ( Window);
  413. return TRUE;
  414. }
  415.  
  416. /******************************************************************************/
  417.  
  418. void SetWindowColor ( struct Window *Window, unsigned color)
  419. {
  420. register unsigned x, y, xcur, ycur;
  421. char in;
  422.    xcur = Window->xcur;
  423.    ycur = Window->ycur;
  424.    Window->textcolor = color;
  425.    for (y=0;y<Window->height;y++) {
  426.     SetCursor ( Window, 0, y);
  427.     for (x=0;x<Window->width;x++) {
  428.         in = ReadPoint ( Window, x, y);
  429.         OutChar ( Window, in);
  430.         }
  431.     }
  432.  Window->xcur = xcur;
  433.  Window->ycur = ycur;
  434.  SetCursor ( Window ,xcur, ycur);
  435. }
  436.  
  437. /******************************************************************************/
  438.  
  439. int AddMenu ( struct Window *Window, struct Menu *Menu)
  440. {
  441.  if ( Window->y!=Window->CRect.y) {
  442.     Window->CRect.y++;
  443.     Window->CRect.height--;
  444.     }
  445.  ((struct Menu *) Window->addinf) = Menu;
  446.  DrawMenubar ( Window);
  447. return 1;
  448. }
  449.  
  450. /******************************************************************************/
  451.  
  452. int DrawMenubar ( struct Window *Window)
  453. {
  454. unsigned ypos=Window->CRect.y,
  455.      color=Window->color, i;
  456. struct Menu *RunMenu = (struct Menu *) Window->addinf;
  457.  
  458.  Window->CRect.y = Window->y;
  459.  Window->textcolor = ((struct Menu *) Window->addinf)->color;
  460.  SetCursor ( Window, 0, 0);
  461.  while ( RunMenu) {
  462.     OutChar ( Window, ' ');
  463.     Text ( Window, RunMenu->title);
  464.     OutChar ( Window, ' ');
  465.     RunMenu = RunMenu->NextMenu;
  466.     }
  467.  for (i=Window->xcur;i<Window->width;i++) OutChar ( Window, ' ');
  468.  Window->CRect.y = ypos;
  469.  Window->textcolor = color;
  470. return TRUE;
  471. }
  472.  
  473. /******************************************************************************/
  474.  
  475. int ShowWindow ( struct Window *Window)
  476. {
  477. int memsize;
  478. int i;
  479. register int far *scrpos, x, bground;
  480.  
  481.  if ( Window->buffer) free ( Window->buffer);
  482.  memsize = Window->width*2 * Window->height;
  483.  if (!(Window->buffer=(char *) malloc ( memsize))) return FALSE;
  484.  bground = (Window->color << 8) + 0x20;
  485.  for (i=0;i<Window->height;i++) {
  486.     _memcpy ( (char far *) Window->buffer+i*Window->width*2,
  487.     (char far *) scrpos = (char far *) (screenptr+Window->y*160+Window->x*2+i*160), Window->width*2);
  488.     for (x=0;x<Window->width;x++) *scrpos++ = bground;
  489.     }
  490. return TRUE;
  491. }
  492.  
  493. /******************************************************************************/
  494.  
  495. int UpdateWindow ( struct Window *Window)
  496. {
  497. register unsigned i;
  498. register char far *lo = screenptr + Window->x*2 + Window->y*160;
  499. struct Border *bord;
  500.  
  501.  if (Window->style & (WNDSTYLE_BORDER|WNDSTYLE_BOLDBORDER)) {
  502.     if ( Window->style & WNDSTYLE_BORDER) bord = &NormalBorder;
  503.         else bord = &BoldBorder;
  504.     *(lo) = bord->nw;
  505.     *(lo + Window->width*2 - 2) = bord->ne;
  506.     *(lo + Window->height*160 - 160) = bord->sw;
  507.     *(lo + Window->height*160 + Window->width*2 - 162) = bord->se;
  508.     for (i=0;i<Window->width-2;i++) {
  509.         *(lo + i*2 + 2) = bord->horz;
  510.         *(lo + i*2 + Window->height*160 -158) = bord->horz;
  511.         }
  512.     for (i=0;i<Window->height-2;i++) {
  513.         *(lo + i*160 + 160) = bord->vert;
  514.         *(lo + i*160 + Window->width*2 + 160 - 2) = bord->vert;
  515.         }
  516.     }
  517. return TRUE;
  518. }
  519.  
  520. /******************************************************************************/
  521.  
  522. int ShowText ( struct Window *Window)
  523. {
  524. char *text = (char *) ((struct Edit *) Window->addinf)->text + ((struct Edit *) Window->addinf)->curpos - Window->xcur;
  525. int curpos = Window->xcur;
  526.  
  527.  OutText ( Window, 0, 0, text, Window->width);
  528.  OutChar ( Window, ' ');
  529.  Window->xcur = curpos;
  530. return TRUE;
  531. }
  532.  
  533. /******************************************************************************/
  534.  
  535. struct Window *CreateWindow ( struct NewWindow *NewWindow)
  536. {
  537. struct Window *Window;
  538. unsigned i=0, a=0;
  539. struct Class *Class = (struct Class *) GetNode ( &ClassNode, 0, GN_FIRST);
  540.  
  541.  if (!(Window = (struct Window *) (char *) malloc (sizeof(struct Window)))) return FALSE;
  542.  
  543.  while ( Class) {
  544.     if (!strcmp(Class->classname,NewWindow->class)) break;
  545.     Class = (struct Class *) GetNode ( &ClassNode, (int) Class, GN_NEXT);
  546.     i++;
  547.     }
  548.  
  549.  if (i==classcount) return FALSE;
  550.  Window->function = Class->function;
  551.  memcpy ( &Window->x, &NewWindow->x, 18);
  552.  Window->name = NewWindow->name;
  553.  Window->buffer = NULL;
  554.  Window->xcur = Window->ycur = 0;
  555.  if (Window->style & (WNDSTYLE_BORDER | WNDSTYLE_BOLDBORDER)) a=1;
  556.  Window->CRect.x = Window->x+a;
  557.  Window->CRect.y = Window->y+a;
  558.  Window->CRect.width = Window->width-2*a;
  559.  Window->CRect.height = Window->height-2*a;
  560.  
  561.  memset ( &Window->ChildNode, 0, sizeof (struct NodeHead));
  562.  if ( Window->MainWindow=NewWindow->MainWindow) AddNode ( &Window->MainWindow->ChildNode, (int) Window);
  563.  AddNode ( &WindowNode, (int) Window);
  564.  
  565.  ShowWindow ( Window);
  566.  UpdateWindow ( Window);
  567.  SendMessage ( Window, WM_CREATE, 0, 0L);
  568.  SendMessage ( Window, WM_PAINT, 0, 0L);
  569. return Window;
  570. }
  571.  
  572. /******************************************************************************/
  573.  
  574. struct Window *CheckMouse ( unsigned far *x, unsigned far *y)
  575. {
  576. struct Window *RunWindow = (struct Window *) GetNode ( &WindowNode, 0, GN_LAST);
  577.   *x /= 8; *y /= 8;
  578.   do {
  579.       if ( PtInRect ( *x, *y, (struct Rect *) &RunWindow->x)) {
  580.     if ( !PtInRect ( *x, *y, (struct Rect *) &RunWindow->CRect)) {
  581.         /*  MoveWindow ( RunWindow);  */
  582.         break;
  583.         }
  584.     *x -= RunWindow->x;
  585.     *y -= RunWindow->y;
  586.     return RunWindow;
  587.     }
  588.      } while (RunWindow = (struct Window *) GetNode (&WindowNode, (int) RunWindow, GN_PREV));
  589. return 0;
  590. }
  591.  
  592. /******************************************************************************/
  593.  
  594. int BringWindowtoTop ( struct Window *Window)
  595. {
  596.  /* PutBackground ( Window); */
  597. }
  598.  
  599. /******************************************************************************/
  600.  
  601. void ExitMainLoop (int Code)
  602.    {
  603.      RetCode = Code;
  604.      ExitLoop = TRUE;
  605.    }
  606.  
  607. /******************************************************************************/
  608.  
  609. int MainWindowProc ()
  610. {
  611. char in, zero;
  612. struct Window *Window = (struct Window *) GetNode ( &WindowNode, 0, GN_LAST);
  613. struct Window *InputWindow, *win, *winbak;
  614. unsigned far *x, far *y, far *buttons, message, prevbutton=0, stat=FALSE;
  615.  
  616. /*  if (mouse=MOUSEINSTALLED ()) MOUSESHOW ();    */
  617.  
  618.   if ( Window->MainWindow) {
  619.     Window = Window->MainWindow;
  620.     InputWindow = (struct Window *) GetNode ( &Window->ChildNode, 0, GN_FIRST);
  621.     }
  622.   else InputWindow = Window;
  623.  
  624.   while (TRUE) {
  625.     if ( cursorchanged) { SetBCursor ( InputWindow); cursorchanged = FALSE; }
  626.     message = 0;
  627.         do {
  628.             if (ExitLoop) {
  629.                 ExitLoop = FALSE;
  630.                 return RetCode;
  631.                 }
  632.         CheckTimer ();
  633.         if ( mouse) {
  634.         /*  MOUSEPOSITION ( y, x, buttons); */
  635.         if ( prevbutton - *buttons)  {
  636.             prevbutton = *buttons;
  637.             if (stat ^= TRUE) {
  638.                 message = WM_LBUTTON;
  639.                 if (winbak=CheckMouse ( x, y))
  640.                     InputWindow = winbak;
  641.                 }
  642.             else message = WM_LBUTTONUP;
  643.             break;
  644.             }
  645.         }
  646.         if (ALT_KEY) {
  647.         while (ALT_KEY);
  648.         menucheck ^= TRUE;
  649.         /* CheckMenu (InputWindow); */
  650.         }
  651.        } while (!kbhit());
  652.     if (!message) {
  653.         in = getch();
  654.         if(!in) { in = getch (); zero = TRUE; }
  655.             else zero = FALSE;
  656.         message = WM_KEYPRESSED;
  657.         }
  658.     else {
  659.         in = 0;
  660.         zero = MAKELONG (*x,*y);
  661.         }
  662.     if (SendMessage (InputWindow, message, (char) in, (long) zero )) continue;
  663.     switch ( in) {
  664.         case 27:
  665.             /*  if (mouse) MOUSEHIDE (); */
  666.             return 0; break;
  667.         case 9:
  668.             if (!(win = (struct Window *) GetNode ( &Window->ChildNode, (int) InputWindow, GN_NEXT))) {
  669.                 if (!(win = (struct Window *) GetNode ( &Window->ChildNode, 0, GN_FIRST))) break;
  670.                 }
  671.             InputWindow = win;
  672.             break;
  673.         }
  674.     }
  675. }
  676.  
  677. /******************************************************************************/
  678.  
  679. long ButtonProc ( WINDOW *Window, unsigned Message, int wParam, long Param)
  680. {
  681. static int TimerInfo;
  682.  
  683.  switch (Message) {
  684.     case WM_CREATE:
  685.         Window->addinf = FALSE;
  686.         break;
  687.  
  688.     case WM_PAINT:
  689.         OutText ( Window, 0, 0, Window->name, strlen ( Window->name));
  690.         break;
  691.  
  692.     case WM_LBUTTON:
  693.         if ( Window->addinf) break;
  694.         /*  if ( mouse) MOUSEHIDE (); */
  695.         SetWindowColor ( Window, ~Window->color);
  696.         Window->addinf = (char *) 1;
  697.         break;
  698.  
  699.     case WM_LBUTTONUP:
  700.         SetWindowColor ( Window, Window->color);
  701.         Window->addinf = FALSE;
  702.         SendMessage ( Window->MainWindow, WM_COMMAND, Window->ID, 0L);
  703.         /*   if (mouse) MOUSESHOW ();    */
  704.         break;
  705.  
  706.     default: return FALSE;
  707.     }
  708.  return TRUE;
  709. }
  710.  
  711. /******************************************************************************/
  712.  
  713. long EditProc ( WINDOW *Window, unsigned Message, int wParam, long Param)
  714. {
  715. struct Edit Edit;
  716. int len;
  717.  
  718.   switch ( Message) {
  719.     case WM_DESTROY:
  720.         free ( Window->addinf);
  721.         break;
  722.  
  723.     case WM_CREATE:
  724.         Window->addinf = (char *) malloc (sizeof (struct Edit));
  725.         ((struct Edit *) Window->addinf)->text = (char *) malloc (((struct Edit *) Window->addinf)->memsize = 32);
  726.         *((struct Edit *) Window->addinf)->text = 0;
  727.         ((struct Edit *) Window->addinf)->pos  = 0;
  728.         ((struct Edit *) Window->addinf)->curpos  = 0;
  729.         ((struct Edit *) Window->addinf)->maxlen  = 64;
  730.         break;
  731.  
  732.     case WM_PAINT:
  733.         ShowText ( Window);
  734.         break;
  735.  
  736.     case EC_SETTEXT:
  737.         strcpy ( ((struct Edit *) Window->addinf)->text, (char *) wParam);
  738.         ((struct Edit *) Window->addinf)->pos  = 0;
  739.         ((struct Edit *) Window->addinf)->curpos  = 0;
  740.         Clear ( Window);
  741.         break;
  742.  
  743.     case EC_GETTEXT:
  744.         strcpy ( (char *) wParam ,((struct Edit *) Window->addinf)->text);
  745.         break;
  746.  
  747.     case EC_SETTEXTMAX:
  748.         ((struct Edit *) Window->addinf)->maxlen  = wParam;
  749.         break;
  750.  
  751.     case EC_CLEAR:
  752.         *(((struct Edit *) Window->addinf)->text) = 0;
  753.         Clear ( Window);
  754.         break;
  755.  
  756.     case WM_KEYPRESSED:
  757.         len = strlen (((struct Edit *) Window->addinf)->text);
  758.         if (Param) {
  759.             switch ( wParam) {
  760.                  case 83:
  761.                      if (((struct Edit *) Window->addinf)->curpos==len) break;
  762.                      strcpy ( ((struct Edit *) Window->addinf)->text + ((struct Edit *) Window->addinf)->curpos, ((struct Edit *) Window->addinf)->text + ((struct Edit *) Window->addinf)->curpos+1);
  763.                      break;
  764.  
  765.                  case 75:
  766.                      if (((struct Edit *) Window->addinf)->curpos) {
  767.                          if ( Window->xcur) Window->xcur--;
  768.                          ((struct Edit *) Window->addinf)->curpos--;
  769.                          }
  770.                      break;
  771.                  case 77:
  772.                      if (((struct Edit *) Window->addinf)->curpos==len) break;
  773.                      if (Window->xcur<Window->width-1) Window->xcur++;
  774.                      ((struct Edit *) Window->addinf)->curpos++;
  775.                      break;
  776.                  }
  777.             ShowText ( Window);
  778.             }
  779.         else
  780.         switch ((int) (wParam)) {
  781.             case 8:
  782.                 if (((struct Edit *) Window->addinf)->curpos==((struct Edit *) Window->addinf)->maxlen) break;
  783.                 if (!len || !((struct Edit *) Window->addinf)->curpos) break;
  784.                 if (*(((struct Edit *) Window->addinf)->text + ((struct Edit *) Window->addinf)->curpos) == 0) {
  785.                     *(((struct Edit *) Window->addinf)->text + ((struct Edit *) Window->addinf)->curpos-1) = '\0';
  786.                     }
  787.                 else strcpy ( ((struct Edit *) Window->addinf)->text + ((struct Edit *) Window->addinf)->curpos - 1, ((struct Edit *) Window->addinf)->text + ((struct Edit *) Window->addinf)->curpos);
  788.                 ((struct Edit *) Window->addinf)->curpos--;
  789.                 if (Window->xcur) Window->xcur--;
  790.                     else { if (len<Window->width/2)
  791.                          Window->xcur = len-2;
  792.                            else Window->xcur = Window->width/2;
  793.                         }
  794.                 ShowText ( Window);
  795.                 break;
  796.  
  797.             default:
  798.                 if ((wParam<32)||(wParam>127)) return FALSE;
  799.                 if (len+1==((struct Edit *) Window->addinf)->maxlen) break;
  800.                 if (len==((struct Edit *) Window->addinf)->memsize-2)
  801.                     ((struct Edit *) Window->addinf)->text = (char *) realloc ( ((struct Edit *) Window->addinf)->text, ((struct Edit *) Window->addinf)->memsize += 16);
  802.                 if ( (*((struct Edit *) Window->addinf)->text+((struct Edit *) Window->addinf)->curpos) == 0) sprintf ( ((struct Edit *) Window->addinf)->text, "%s%c\0", ((struct Edit *) Window->addinf)->text, (char) wParam);
  803.                   else { strrcopy ( ((struct Edit *) Window->addinf)->text + ((struct Edit *) Window->addinf)->curpos + 1, ((struct Edit *) Window->addinf)->text + ((struct Edit *) Window->addinf)->curpos);
  804.                      *(((struct Edit *) Window->addinf)->text + ((struct Edit *) Window->addinf)->curpos) = (char) wParam;
  805.                      *(((struct Edit *) Window->addinf)->text + ((struct Edit *) Window->addinf)->curpos+len) = 0;
  806.                      }
  807.                 ((struct Edit *) Window->addinf)->curpos++;
  808.                 if ( Window->xcur+2 < Window->width) Window->xcur++;
  809.                 ShowText ( Window);
  810.                 }
  811.         break;
  812.     default: return FALSE;
  813.     }
  814.  return TRUE;
  815. }
  816.  
  817. /******************************************************************************/
  818.  
  819. long ListBoxProc ( WINDOW *Window, unsigned Message, int wParam, long Param)
  820. {
  821. struct ListBox *lBox;
  822. char *text;
  823. int i;
  824.  
  825.  switch (Message) {
  826.     case WM_CREATE:
  827.         Window->addinf = (char *) malloc (sizeof(struct ListBox));
  828.         memset (Window->addinf,0,sizeof(struct ListBox));
  829.         lBox->count = lBox->pos = lBox->displayoffset = 0;
  830.         AddNode (&NodeListHead,(int) Window);
  831.         break;
  832.  
  833.     case WM_KEYPRESSED:
  834.         if (!(lBox = (struct ListBox *) Window->addinf)) break;
  835.         switch (wParam) {
  836.             case 72:
  837.                 if (!lBox->displayoffset) break;
  838.                 lBox->displayoffset--;
  839.                 ScrollWindow ( Window, 0,1);
  840.                 for (i=0,text=(char *) GetNode(&lBox->TextNodeHead,0,GN_FIRST);i<lBox->displayoffset;i++,text=(char *) GetNode(&lBox->TextNodeHead,(int) text,GN_NEXT))
  841.                 OutText ( Window, 0, 0, text, Window->width);
  842.                 break;
  843.             case 80:
  844.                 if (lBox->displayoffset+lBox->pos == Window->height) break;
  845.                 ScrollWindow ( Window, 0,-1);
  846.                 for (i=0,text=(char *) GetNode(&lBox->TextNodeHead,0,GN_FIRST);i<(lBox->displayoffset+lBox->pos);i++,text=(char *) GetNode(&lBox->TextNodeHead,(int) text,GN_NEXT))
  847.                 OutText ( Window, 0, 0, text, Window->width);
  848.                 break;
  849.             default: return FALSE;
  850.             }
  851.         break;
  852.  
  853.     case LB_ADDTEXT:
  854.         if (!(lBox = (struct ListBox *) Window->addinf)) break;
  855.         AddNode (&lBox->TextNodeHead,wParam);
  856.         lBox->count++;
  857.         SendMessage (Window,WM_PAINT,0,0L);
  858.         break;
  859.  
  860.     case WM_PAINT:
  861.         if (!(lBox = (struct ListBox *) Window->addinf)) break;
  862.         for (i=0,text=(char *) GetNode(&lBox->TextNodeHead,0,GN_FIRST);text;text=(char *) GetNode(&lBox->TextNodeHead,(int) text,GN_NEXT),i++) {
  863.             if ((i<lBox->displayoffset) || (i>Window->height)) continue;
  864.             OutText ( Window, 0, i-lBox->displayoffset, text, Window->width);
  865.             }
  866.         break;
  867.  
  868.     default: return FALSE;
  869.     }
  870. return TRUE;
  871. }
  872.  
  873. /******************************************************************************/
  874.  
  875. main ()
  876. {
  877.  InitAll ();
  878.   WinMain ();
  879.  CloseAll ();
  880. }
  881.